package cloud.tianai.ram.policy.client.autoconfiguration;

import cloud.tianai.ram.policy.client.ActionHolder;
import cloud.tianai.ram.policy.client.CurrentUserStatementProvider;
import cloud.tianai.ram.policy.client.aop.ActionAnnotationAdvisor;
import cloud.tianai.ram.policy.client.aop.ActionInterceptor;
import cloud.tianai.ram.policy.common.handler.PermissionHandler;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: 天爱有情
 * @date 2022/3/23 16:43
 * @Description Ram自动装配器
 */
@Configuration
public class RamClientAutoConfiguration {


    @Bean
    @ConditionalOnMissingBean
    public ActionHolder actionHolder() {
        return new ActionHolder();
    }


    @Bean
    @ConditionalOnMissingBean
    public ActionInterceptor actionInterceptor(PermissionHandler permissionHandler,
                                               CurrentUserStatementProvider currentUserPermissionProvider,
                                               ActionHolder actionHolder) {
        return new ActionInterceptor(permissionHandler, currentUserPermissionProvider, actionHolder);
    }

    @Bean
    @ConditionalOnMissingBean
    public ActionAnnotationAdvisor actionAnnotationAdvisor(ActionInterceptor actionInterceptor) {
        return new ActionAnnotationAdvisor(actionInterceptor);
    }
}
